import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:grab_the_order/core/values/app_styles.dart';
import 'splash_controller.dart';

class SplashView extends GetView<SplashController> {
  const SplashView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: const BoxDecoration(gradient: kGradientBackground),
        child: Stack(
          children: [
            _buildLogo(),
            // 【已修改】使用Obx包裹，根据条件决定是否显示跳过按钮
            Obx(() {
              if (controller.showSkipButton.value) {
                return _buildSkipButton();
              } else {
                // 如果不需要显示，则返回一个空的占位容器
                return const SizedBox.shrink();
              }
            }),
          ],
        ),
      ),
    );
  }

  Widget _buildLogo() {
    return const Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(
            Icons.rocket_launch_outlined,
            size: 100,
            color: Colors.white,
          ),
          SizedBox(height: 20),
          Text(
            "抢单助手",
            style: TextStyle(
              fontSize: 32,
              fontWeight: FontWeight.bold,
              color: Colors.white,
              letterSpacing: 2,
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildSkipButton() {
    return Positioned(
      top: Get.mediaQuery.padding.top + 10,
      right: 20,
      child: GestureDetector(
        onTap: controller.skipCountdown,
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
          decoration: BoxDecoration(
            color: Colors.black.withOpacity(0.2),
            borderRadius: BorderRadius.circular(20),
          ),
          child: Obx(
            () => Text(
              '${controller.countdown.value} 跳过',
              style: const TextStyle(color: Colors.white, fontSize: 14),
            ),
          ),
        ),
      ),
    );
  }
}
